//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

import { mapGetters } from "vuex";
import template from "./moneyTransformTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  data() {
    return {
      loadingFlag: false,
      fixData: ["现金余额"],
      gameList: [], //游戏列表
      rollOut: ["现金余额"], //转出
      rollIn: [], //转入
      rollNum: null, //金额
      cash: 0,
      sum_money: 0,
      token: localStorage.getItem("token"),
      rollFlag: false,
    };
  },
  created() {
    this._getGameList(1);
  },
  computed: {
    ...mapGetters(["userInfo"]),
    rollData() {
      //表格的总数据
      let arr = [];
      let game = [];
      for (let i = 0; i < this.gameList.length; i++) {
        game.push(this.gameList[i].game_name);
      }
      arr.push(this.fixData.concat(game));
      return arr;
    },
  },
  methods: {
    toGame(plat_flag) {
      this.$http
        .post(this.urlRequest + "?m=api&c=game&a=getGameUrl", {
          plat_flag: plat_flag,
          token: this.token,
        })
        .then((res) => {
          if (res.status == 0) {
            let w = window;
            let _w = window;
            let w_lottery = window;
            let style = "width=1270px, height=950px, scrollbars=yes";
            if (w != w.parent) {
              w = w.parent == w.parent.parent ? w.parent : w.parent.parent;
            }
            w_lottery = w.open(res.data.gameUrl, "game_window", style);
            w_lottery.focus();
          }
        });
    },
    _getGameList(id) {
      //获取游戏分类及列表
      this.$vux.loading.show();
      let vm = this;
      let dataMess = {};
      dataMess.token = vm.token;

      // dataMess.game_plat_id = 1
      dataMess.game_plat_id = id;
      // if(id){
      //   dataMess.game_plat_id = id;
      // }else{
      //   dataMess.game_plat_id = 1;
      // }
      vm.$http
        .post(
          this.urlRequest + "?m=api&c=game&a=getGamePlatForAmtLimit",
          dataMess
        )
        .then((res) => {
          if (res.code == -10000) {
            return;
          }
          if (res.status == 0) {
            vm.cash = res.data.balance_count;
            vm.sum_money = res.data.balance_usable;
            // if(dataMess.game_plat_id!=1){
            //   for(let i=0;i<vm.gameList.length;i++){
            //     if(vm.gameList[i].game_plat_id==id){
            //       for(var j=0;j<res.data.plat_list.length;j++){
            //         if(res.data.plat_list[j].game_plat_id==id){
            //           vm.gameList[i] = res.data.plat_list[j];
            //         }
            //       }
            //     }
            //   }
            // }else{
            vm.gameList = res.data.plat_list;
            // }
          } else {
            vm.$vux.toast.show({
              text: res.ret_msg,
            });
          }
          this.$vux.loading.hide();
        });
    },
    rollOutFun() {
      let vm = this;
      var newRoll = JSON.parse(JSON.stringify(vm.rollIn));
      vm.rollIn = [];
      if (vm.rollOut[0] == "现金余额") {
        console.log("left");
        if (newRoll[0] == "现金余额") {
          vm.rollIn.push(vm.gameList[0].game_name);
        } else {
          vm.rollIn.push(newRoll[0]);
        }
      } else {
        vm.rollIn.push("现金余额");
      }
    },
    rollInFun() {
      let vm = this;
      var newRoll = JSON.parse(JSON.stringify(vm.rollOut));
      vm.rollOut = [];
      if (vm.rollIn[0] == "现金余额") {
        console.log("right");
        if (newRoll[0] == "现金余额") {
          vm.rollOut.push(vm.gameList[0].game_name);
        } else {
          vm.rollOut.push(newRoll[0]);
        }
      } else {
        vm.rollOut.push("现金余额");
      }
    },
    changeRoll() {
      let vm = this;
      let arr = vm.rollOut;
      vm.rollOut = vm.rollIn;
      vm.rollIn = arr;
    },
    rollAll(id) {
      //一键转入
      let vm = this;
      if (vm.loadingFlag) {
        return false;
      }
      if (vm.sum_money == 0) {
        vm.$vux.toast.show({
          text: "现金余额不足",
        });
        return false;
      }
      if (vm.sum_money == null || isNaN(vm.sum_money)) {
        vm.$vux.toast.show({
          text: "请输入正确的转账金额",
        });
        return false;
      }
      let dataMess = {};
      dataMess.token = vm.token;
      dataMess.money = vm.sum_money;
      dataMess.type = 1;
      dataMess.game_plat_id = id;

      vm.$http
        .post(this.urlRequest + "?m=api&c=game&a=transfer", dataMess)
        .then((res) => {
          vm.$vux.toast.show({
            text: res.ret_msg,
          });
          if (res.status == 0) {
            this._getGameList(1);
          }
        });
    },
    submit() {
      let vm = this;
      if (vm.loadingFlag) {
        return false;
      }
      let dataMess = {};
      dataMess.token = vm.token;
      dataMess.money = vm.rollNum;
      let thisRoll = vm.rollIn[0];
      if (vm.rollIn[0] == "现金余额") {
        //下分
        dataMess.type = 2;
        thisRoll = vm.rollOut[0];
      } else {
        //上分
        dataMess.type = 1;
        thisRoll = vm.rollIn[0];
        if (vm.sum_money == 0) {
          vm.$vux.toast.show({
            text: "现金余额不足",
          });
          return false;
        }
      }
      if (vm.rollNum == null || isNaN(vm.rollNum)) {
        vm.$vux.toast.show({
          text: "请输入正确的转账金额",
        });
        return false;
      }

      for (let i = 0; i < vm.gameList.length; i++) {
        if (vm.gameList[i].game_name == thisRoll) {
          dataMess.game_plat_id = vm.gameList[i].game_plat_id;
        }
      }
      vm.loadingFlag = true;
      vm.$http
        .post(this.urlRequest + "?m=api&c=game&a=transfer", dataMess)
        .then((res) => {
          vm.loadingFlag = false;
          if (res.code == -10000) {
            return;
          }
          vm.$vux.toast.show({
            text: res.ret_msg,
          });
          if (res.status == 0) {
            vm.rollNum = null;
            this._getGameList(dataMess.game_plat_id);
          }
        });
    },
  },
  watch: {
    rollData() {
      let vm = this;
      vm.rollIn = [];
      vm.rollIn.push(vm.gameList[0].game_name);
    },
  },
};

// WEBPACK FOOTER //
// ./src/components/wallet/moneyTransform/moneyTransform.vue
